package com.xinggq.auth.service.exception;

import com.xinggq.auth.api.exception.AuthException;
import com.xinggq.common.CommonResult;
import com.xinggq.common.enums.ResponseEnum;
import com.xinggq.common.exception.BaseGlobalExceptionHandler;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 认证中心全局异常处理器
 * 继承基础异常处理器，扩展认证相关的异常处理
 *
 * @author xinggq
 * @since 2025-10-21
 */
@Slf4j
@RestControllerAdvice
@Order(10) // 设置较高优先级，优先处理认证相关异常
public class GlobalExceptionHandler extends BaseGlobalExceptionHandler {

  /**
   * 处理认证异常
   */
  @ExceptionHandler(AuthException.class)
  public CommonResult<Object> handleAuthException(AuthException e, HttpServletRequest request) {
    log.error("认证异常 - 请求路径: {}, 错误码: {}, 错误信息: {}",
        request.getRequestURI(), e.getCode(), e.getMessage(), e);
    return CommonResult.result(e.getCode(), e.getMessage()).setData(e.getData());
  }


}